﻿/*-----------------------------------------------------------------------
 * <copyright file="WorkEfficiencyQueryControl.xaml.cs" company="O-RID">
 *     Copyright (c)2010 O-RID Co.,Ltd.
 * </copyright>
 * <author>Zhang jun</author>
 * <summary>
 *              稼働率查询
 *              
 *     引用服务：WCFServers.MatterQueryRef
 *     服务功能：数据查询
 *   
 *     引用服务：WCFLog4Ref.WCFLog4Client
 *     服务功能：记录日志
 * 
 *              作成日：08/23/2010
 *                      08/24/2010 增加 设置图表的颜色
 *                      09/28/0210 增加 分页记录数可自定义
 *                      10/14/2010 修改 导出功能异常
 * </summary>
 *----------------------------------------------------------------------- 
 */
namespace Orid.Management.Statistics.OperatorUnitMangement.EfficiencyRelated.ReportWorkEfficiencyQuery
{
    using System;
    using System.Collections.Generic;
    using System.Threading;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Controls.DataVisualization.Charting;
    using System.Windows.Data;
    using System.Windows.Media;
    using Orid.Management.Statistics.OperatorUnitMangement.Common.Export;
    using Orid.Management.Statistics.OperatorUnitMangement.Common.FunctionList;
    using Orid.Management.Statistics.OperatorUnitMangement.Common.SearchCtrl;
    using Orid.Management.Statistics.OperatorUnitMangement.WCFServers.MatterQueryRef;
    using childWindow = Orid.Management.Statistics.OperatorUnitMangement.Common.Window;
    using Wcf = Orid.Management.Statistics.OperatorUnitMangement.Common.Service;
    using Orid.Management.Statistics.OperatorUnitMangement.Common.SytleSet;

    /// <summary>
    /// 稼働率查询
    /// </summary>
    public partial class WorkEfficiencyQueryControl : UserControl
    {
        #region 全局变量

        /// <summary>
        /// 当前查询框的名字（日志用）
        /// </summary>
        private string ctrlName = " 稼働率";

        /// <summary>
        /// 查询区域对象
        /// USEfficSelContainer
        /// </summary>
        private Common.SearchCtrl.USEfficSelContainer workEfficSelcontainer;

        /// <summary>
        /// 消息子窗体 errorMessbox
        /// </summary>
        private childWindow.MessageBox errorMessbox = null;

        /// <summary>
        /// 日志服务定义
        /// wcfLogClient
        /// </summary>
        private WCFLog4Ref.WCFLog4Client wcfLogClient = null;

        /// <summary>
        /// 分页控件
        /// PagedCollectionView
        /// </summary>
        private PagedCollectionView pcv;

        /// <summary>
        /// 记录要导出的数据
        /// </summary>
        List<string[]> dataListToCSV = null;

        /// <summary>
        /// 稼动率图表
        /// </summary>
        Chart workEfficChart = null;

        /// <summary>
        /// 稼动率图表 X轴的最大长度
        /// </summary>
        double workEfficChartXMaxWidth = 0;

        /// <summary>
        /// DataGrid数据源
        /// </summary>
        List<string[]> getListSource = null;

        /// <summary>
        /// 稼动率 图表数据源列表
        /// </summary>
        List<List<ClientChartData>> workEfficChartSource = null;

        #endregion 全局变量
        /// <summary>
        /// 稼働率查询 构造函数
        /// </summary>
        public WorkEfficiencyQueryControl(USEfficSelContainer workEfficSelcontainer)
        {
            InitializeComponent();

            // 引用主题
            ((App)Application.Current).SetTheme((Grid)LayoutRoot);
            this.dgWrokEfficient.HeadersVisibility = DataGridHeadersVisibility.All;//同时显示DataGrid的行头与列头

            this.workEfficSelcontainer = workEfficSelcontainer;

            this.InitField();

            #region 查询设置
            Command.Matter.WorkEfficiencyQuery queryCommand = new Command.Matter.WorkEfficiencyQuery(workEfficSelcontainer);

            queryCommand.ExecOver -= new EventHandler<SelectReportWorkEfficiencyQueryInforCompletedEventArgs>(queryCommand_ExecOver);
            queryCommand.ExecBegin -= new EventHandler<EventArgs>(this.QueryCommand_ExecBegin);

            queryCommand.ExecOver += new EventHandler<SelectReportWorkEfficiencyQueryInforCompletedEventArgs>(queryCommand_ExecOver);
            queryCommand.ExecBegin += new EventHandler<EventArgs>(this.QueryCommand_ExecBegin);

            this.workEfficSelcontainer.QueryCcommand = queryCommand;
            #endregion 查询设置

            #region 导出设置
            //导出
            Command.DateExport exportCommand = new Command.DateExport();
            //导出开始
            exportCommand.ExecBegin += new EventHandler<EventArgs>(this.ExportCommand_ExecBegin);

            this.workEfficSelcontainer.ExportComand = exportCommand;

            #endregion 导出设置

            //查询按钮可用
            this.workEfficSelcontainer.btnUnitSelect.IsEnabled = true;
            //导出按钮可用
            this.workEfficSelcontainer.btnExport.IsEnabled = true;

            this.Loaded += new RoutedEventHandler(WorkEfficiencyQueryControl_Loaded);

            // 设置背景色
            LayoutRoot.Background = new SolidColorBrush(Color.FromArgb(255, 243, 244, 245));

        }

        void WorkEfficiencyQueryControl_Loaded(object sender, RoutedEventArgs e)
        {
            App.Current.Host.Content.Resized -= new EventHandler(Content_Resized);
            App.Current.Host.Content.Resized += new EventHandler(Content_Resized);
            this.nuPageSize.IsEnabled = true; //分页数量 09/28/2010 Add
        }


        /// <summary>
        /// 变量初始化方法  InitField
        /// </summary>
        private void InitField()
        {
            this.errorMessbox = new childWindow.MessageBox();
            this.wcfLogClient = Wcf.Service.Log4;
            this.dataListToCSV = new List<string[]>();

            this.workEfficChart = new Chart();

            this.getListSource = new List<string[]>();
            this.workEfficChartSource = new List<List<ClientChartData>>();
        }

        #region 查询符合条件的OP信息

        /// <summary>
        /// 查询符合条件的OP信息(查询按钮)
        /// WCFOPPEntryClient_SelectJobRateQueryInforCompleted
        /// </summary>
        /// <param name="sender">sender of object</param>
        /// <param name="e">e type of SelectReportWorkEfficiencyQueryInforCompletedEventArgs</param>
        /// <value>WCF数据源中obRateData类，增加 DJobChart/EJobChart 属性（图表数据）</value>
        private void queryCommand_ExecOver(object sender, SelectReportWorkEfficiencyQueryInforCompletedEventArgs e)
        {
            try
            {
                if (e.Error == null)
                {
                    if (e.Result.Count > 0)
                    {
                        workEfficChartXMaxWidth = 0;

                        #region ----把传来的e.Result变成List<String[]>的形式----
                        
                        // DataGrid数据源
                        this.getListSource.Clear();
                        // 稼动率 图表数据源列表
                        this.workEfficChartSource.Clear();

                        //X轴长度
                        workEfficChartXMaxWidth = 0;

                        //一共有多少个outDateTime
                        int outDateTimeNum = e.Result[0].OutDateTime.Count;
                        //一共有多少个属性
                        int attributeNum = e.Result[0].GetType().GetProperties().Length;

                        //列数
                        int m = 0;
                        foreach (WorkEfficiencyQueryData setClass in e.Result)
                        {
                            //WCF数据源中WorkEfficiencyQueryData类，
                            //WrokEffChart/AttendanceTimeChart/ProcessingTimeChart 属性（图表数据）
                            //所以，由attributeNum - 4
                            String[] strAdd = new String[outDateTimeNum + attributeNum - 4];

                            strAdd[m++] = setClass.Project; //集計項目 [0]

                            //日期 //从[1]开始
                            for (int j = 0; j < setClass.OutDateTime.Count; j++)
                            {
                                strAdd[m++] = setClass.OutDateTime[j].ToString();
                            }

                            strAdd[m++] = setClass.Average; //平均 [日期的最后一个下标加1]
                            getListSource.Add(strAdd);
                            m = 0;

                            #region 图表数据源

                            /*
                             * 稼働率(処理時間)、出勤時間(H)、処理時間(H) 图表数据源
                             * 对E.RESULT的数据进行转换 
                             * 将E.RESULT结果中的每一个 稼働率(処理時間)、出勤時間(H)、処理時間(H) 
                             * 合成单独的数据列表workEfficChartSource
                             * */

                            //开始日期
                            DateTime workEfficStartDate = this.workEfficSelcontainer.StartDataTime;

                            switch (setClass.Project.Trim())
                            {
                                //出勤時間(H)
                                case "出勤時間(H)":
                                    
                                    List<ClientChartData> valueAttendanceTimeAdd = new List<ClientChartData>();

                                    for (int i = 0; i < setClass.AttendanceTimeChart.Count; i++)
                                    {
                                        if (!string.IsNullOrEmpty(setClass.AttendanceTimeChart[i]))
                                        {
                                            ClientChartData AttendanceTimeChartData = new ClientChartData();

                                            AttendanceTimeChartData.MatterName = setClass.Project;
                                            //日期值
                                            AttendanceTimeChartData.ChartDate = Convert.ToDateTime(workEfficStartDate.Date.ToString("yyyy-M-d"));
                                            //日期对应的数值
                                            AttendanceTimeChartData.Value = Convert.ToDouble(setClass.AttendanceTimeChart[i].ToString());
                                            
                                            valueAttendanceTimeAdd.Add(AttendanceTimeChartData);
                                        }
                                        workEfficStartDate = workEfficStartDate.AddDays(1);
                                    }
                                    //将空数据排除
                                    if (valueAttendanceTimeAdd.Count > 0)
                                    {
                                        workEfficChartSource.Add(valueAttendanceTimeAdd);
                                    }
                                    break;

                                //処理時間(H)
                                case "処理時間(H)":

                                    List<ClientChartData> valueprocessingTimeAdd = new List<ClientChartData>();

                                    for (int i = 0; i < setClass.ProcessingTimeChart.Count; i++)
                                    {

                                        if (!string.IsNullOrEmpty(setClass.ProcessingTimeChart[i]))
                                        {
                                            ClientChartData ProcessingTimeChartData = new ClientChartData();

                                            ProcessingTimeChartData.MatterName = setClass.Project;
                                            //日期值
                                            ProcessingTimeChartData.ChartDate = Convert.ToDateTime(workEfficStartDate.Date.ToString("yyyy-M-d"));

                                            //日期对应的数值
                                            ProcessingTimeChartData.Value = Convert.ToDouble(setClass.ProcessingTimeChart[i].ToString());
                                            valueprocessingTimeAdd.Add(ProcessingTimeChartData);
                                        }

                                        workEfficStartDate = workEfficStartDate.AddDays(1);
                                    }
                                    //将空数据排除
                                    if (valueprocessingTimeAdd.Count > 0)
                                    {
                                        workEfficChartSource.Add(valueprocessingTimeAdd);
                                    }
                                    break;

                                //稼働率(処理時間)
                                case "稼働率(処理時間)":

                                    List<ClientChartData> valueworkEfficChartAdd = new List<ClientChartData>();

                                    for (int i = 0; i < setClass.WrokEffChart.Count; i++)
                                    {
                                        if (!string.IsNullOrEmpty(setClass.WrokEffChart[i]))
                                        {
                                            ClientChartData WrokEffTimeChartData = new ClientChartData();

                                            WrokEffTimeChartData.MatterName = setClass.Project;
                                            //日期值
                                            WrokEffTimeChartData.ChartDate = Convert.ToDateTime(workEfficStartDate.Date.ToString("yyyy-M-d"));
                                            //日期对应的数值
                                            WrokEffTimeChartData.Value = Convert.ToDouble(setClass.WrokEffChart[i].ToString());

                                            valueworkEfficChartAdd.Add(WrokEffTimeChartData);
                                        }

                                        workEfficStartDate = workEfficStartDate.AddDays(1);
                                    }
                                    //将空数据排除
                                    if (valueworkEfficChartAdd.Count > 0)
                                    {
                                        workEfficChartSource.Add(valueworkEfficChartAdd);
                                    }

                                    break;
                            }

                            #endregion 图表数据源
                        }

                        //稼动率图表X轴的长度 = 单个数据长度 * 日期间隔天数
                        //DatePicker控件如果是默认选项，日期加当前时间
                        //如果不是默认选项，日期加00：00：00
                        workEfficChartXMaxWidth = 65.0 *
                            FunctionClass.DateDiff(
                                        this.workEfficSelcontainer.dpDateFrom.SelectedDate.Value,
                                        this.workEfficSelcontainer.dpDateTo.SelectedDate.Value
                                                    );

                        #endregion ----把传来的e.Result变成List<String[]>的形式----

                        // 把转换的LIST给 pcv 作为分页源
                        this.pcv = new PagedCollectionView(getListSource);
                        this.pcv.PageSize = Convert.ToInt32(this.nuPageSize.Value);

                        this.dgWrokEfficient.ItemsSource = null;
                        this.dpDataPage.DataContext = null;

                        #region 动态生成 DataGarid

                        //清除之前动态生成的列
                        FunctionClass.clearColumn(this.dgWrokEfficient, 1);

                        this.dgWrokEfficient.ItemsSource = this.pcv;
                        this.dpDataPage.DataContext = this.pcv;

                        //记录LIST<STRING[]>中，日期字段的对应下标号。
                        int colNum = 0;

                        // 动态生成日期列字段
                        for (int i = 0; i < outDateTimeNum; i++)
                        {
                            //在此LIST 中 日期字段的对应下标号从[2]开始。
                            colNum = 1 + i;

                            //转换为日式日期
                            string str = FunctionClass.setDataTimeFormat(this.workEfficSelcontainer.StartDataTime);

                            DataGridTextColumn templateColumn = new DataGridTextColumn();
                            templateColumn.Header = str;
                            templateColumn.Binding = new Binding("[" + colNum + "]");

                            //绑定单元格样式
                            templateColumn.CellStyle = App.Current.Resources["DataGrid_Cell_Right"] as Style;

                            this.dgWrokEfficient.Columns.Add(templateColumn);

                            //天数加1（主要是为了取下一天的日期做表头）
                            this.workEfficSelcontainer.StartDataTime = this.workEfficSelcontainer.StartDataTime.AddDays(1);
                        }

                        // 平均 列
                        DataGridTextColumn templateColumnAVG = new DataGridTextColumn();
                        templateColumnAVG.Header = "平均";
                        colNum++;//平均 [日期的最后一个下标加1]
                        templateColumnAVG.Binding = new Binding("[" + colNum + "]");

                        //绑定单元格样式
                        templateColumnAVG.CellStyle = App.Current.Resources["DataGrid_Cell_Right"] as Style;
                        //将列加到DataGrid中
                        dgWrokEfficient.Columns.Add(templateColumnAVG);

                        //冻结1列
                        this.dgWrokEfficient.FrozenColumnCount = 1;

                        #endregion 动态生成 DataGarid

                        #region 图形数据源绑定
                        
                        ////***稼动率 数据源绑定****
                        workEfficChart.Axes.Clear();
                        workEfficChart.Series.Clear();

                        Action<Chart> chartModifier = (chart) =>
                        {
                            //----横---CategoryAxis
                            DisplayAxis dataAxis = new DateTimeAxis
                            {
                                Orientation = AxisOrientation.X,
                                //Title = "日期",
                                AxisLabelStyle = GetChartStyle.GetChartAxleStyle("x",null), 
                                FontStyle = FontStyles.Normal,
                                ShowGridLines = true,
                            };

                            dataAxis.MaxWidth = workEfficChartXMaxWidth; //设置X轴的最大长度
                            workEfficChart.Axes.Add(dataAxis);

                            //---竖---
                            IAxis valueAxis = new LinearAxis
                            {
                                Orientation = AxisOrientation.Y,
                                //Title = "百分率",
                                FontStyle = FontStyles.Normal,
                                Minimum = 0,
                                Maximum = 100,
                                AxisLabelStyle = GetChartStyle.GetChartAxleStyle("y", "%"), 
                                ShowGridLines = true
                            };

                            workEfficChart.Axes.Add(valueAxis);
                        };
                        chartModifier(workEfficChart);

                        //自定义Y轴
                        IRangeAxis rangeYAxis = new LinearAxis
                        {
                            Orientation = AxisOrientation.Y,//指定为Y轴 
                            Location = AxisLocation.Right,//呈现在右侧
                            //Title = "时间(H)",
                            FontSize = 12,
                            //设置轴的区间
                            Minimum = 0,
                            AxisLabelStyle = GetChartStyle.GetChartAxleStyle("Y","H"), 
                            //设置颜色
                            //背景区域色
                            //Background = new SolidColorBrush(Color.FromArgb(80, 255, 255, 100)),
                            //Y轴字体色
                            Foreground = new SolidColorBrush(Colors.Black),
                        };

                        foreach (List<ClientChartData> workEfficList in workEfficChartSource)
                        {
                            switch (workEfficList[0].MatterName.Trim())
                            {
                                ///两个柱型图，绑定自定义Y轴

                                //柱型图
                                case "出勤時間(H)":
                                    ColumnSeries series1 = new ColumnSeries()
                                     {
                                         ItemsSource = workEfficList,
                                         //----横---
                                         IndependentValueBinding = new System.Windows.Data.Binding("ChartDate"),
                                         //---竖---
                                         DependentValueBinding = new System.Windows.Data.Binding("Value"),

                                         Title = workEfficList[0].MatterName,
                                         //颜色设置 08/24/2010
                                         DataPointStyle = GetChartStyle.GetChartColorStyle(workEfficList[0].MatterName),

                                         DependentRangeAxis = rangeYAxis,//绑定的RangeYAxis会自动显示在Chart中
                                     };
                                    workEfficChart.Series.Add(series1);
                                    break;

                                case "処理時間(H)":
                                    ColumnSeries series2 = new ColumnSeries()
                                     {
                                         ItemsSource = workEfficList,
                                         //----横---
                                         IndependentValueBinding = new System.Windows.Data.Binding("ChartDate"),
                                         //---竖---
                                         DependentValueBinding = new System.Windows.Data.Binding("Value"),

                                         Title = workEfficList[0].MatterName,
                                         //颜色设置 08/24/2010
                                         DataPointStyle = GetChartStyle.GetChartColorStyle(workEfficList[0].MatterName),

                                         DependentRangeAxis = rangeYAxis,//绑定的RangeYAxis会自动显示在Chart中
                                     };
                                    workEfficChart.Series.Add(series2);
                                    break;

                                case "稼働率(処理時間)":
                                    LineSeries line = new LineSeries()
                                    {
                                        ItemsSource = workEfficList,
                                        //----横---
                                        IndependentValueBinding = new System.Windows.Data.Binding("ChartDate"),
                                        //---竖---
                                        DependentValueBinding = new System.Windows.Data.Binding("Value"),
                                        //颜色设置 08/24/2010
                                        DataPointStyle = GetChartStyle.GetChartColorStyle(workEfficList[0].MatterName),

                                        Title = workEfficList[0].MatterName,
                                    };
                                    workEfficChart.Series.Add(line);
                                    break;
                            }
                        }
                        
                        RefreshChartShowSize();

                        workEfficChart.Title = "日別稼働率";

                        this.borderWrokEfficient.Child = null;
                        this.borderWrokEfficient.Child = workEfficChart;

                        #endregion 图形数据源绑定

                        // dataListToCSV记录 导出数据的内容
                        this.dataListToCSV = null;
                        this.dataListToCSV = getListSource;

                        //查询按钮可用
                        this.workEfficSelcontainer.btnUnitSelect.IsEnabled = true;

                        Dispatcher.BeginInvoke(() => DataContext = false);
                        this.nuPageSize.IsEnabled = true; //分页数量 09/28/2010 Add

                        this.wcfLogClient.InfoAsync(((App)Application.Current).LogStr + 
                                                            "在 "+this.ctrlName +" 中查询记录" +
                                                            workEfficSelcontainer.WhereIntorLogs);
                    }
                    else
                    {
                        this.dgWrokEfficient.ItemsSource = null;
                        this.dpDataPage.DataContext = null;

                        this.dataListToCSV = null;

                        this.wcfLogClient.InfoAsync(((App)Application.Current).LogStr +
                                                        "在 "+this.ctrlName +" 中没有查询到记录" +
                                                        workEfficSelcontainer.WhereIntorLogs);
                        throw new Exception(this.ctrlName +" 查询中没有可显示的OP数据");
                    }
                }
                else
                {
                    throw new Exception("queryCommand_ExecOver服务返回值有错" + e.Error.Message.ToString());
                }
            }
            catch (Exception exce)
            {
                Dispatcher.BeginInvoke(() => DataContext = false);
                this.nuPageSize.IsEnabled = true; //分页数量 09/28/2010 Add

                string exceptionStr = FunctionClass.GetMessageInformation(exce);

                //查询按钮可用
                this.workEfficSelcontainer.btnUnitSelect.IsEnabled = true;

                this.wcfLogClient.ErrorAsync(((App)Application.Current).LogStr + 
                                                        ctrlName +
                                                        exceptionStr +
                                                        workEfficSelcontainer.WhereIntorLogs);
                FunctionClass.ShowMessageBox(
                   this.errorMessbox,
                   1,
                   "提示",
                   exceptionStr,
                   Colors.Gray,
                   true,
                   Visibility.Visible,
                   Visibility.Collapsed);
                return;
            }
        }

        #endregion 查询符合条件的OP信息(查询按钮)

        #region BusyBar
        /// <summary>
        /// 让BusyBar开始
        /// SetBusyBar
        /// </summary>
        /// <param name="busySeconds">busy秒数 busysecond</param>
        public void SetBusyBar(int busySeconds)
        {
            int delayMilliseconds = 2;
            biBusyBar.DisplayAfter = TimeSpan.FromMilliseconds(delayMilliseconds);

            DataContext = true;
            this.nuPageSize.IsEnabled = false; //分页数量 09/28/2010 Add

            ThreadPool.QueueUserWorkItem((state) =>
            {
                Thread.Sleep(busySeconds * 1000);
            });
        }

        /// <summary>
        /// 查询开始事件
        /// QueryCommand_ExecBegin
        /// </summary>
        /// <param name="sender">sender of object</param>
        /// <param name="e">e type of RoutedEventArgs</param>
        private void QueryCommand_ExecBegin(object sender, EventArgs e)
        {
            this.SetBusyBar(100);
        }
        #endregion BusyBar

        #region 数据导出

        /// <summary>
        /// 导出开始
        /// ExportCommand_ExecBegin
        /// </summary>
        /// <param name="sender">sender of object</param>
        /// <param name="e">e type of EventArgs</param>
        private void ExportCommand_ExecBegin(object sender, EventArgs e)
        {
            this.ExportDate();
        }

        /// <summary>
        /// 导出 按钮  
        /// ExportDate
        /// </summary>        
        private void ExportDate()
        {
            try
            {
                //设置 查询界面 的 数据导出 可用
                this.workEfficSelcontainer.btnExport.IsEnabled = true;

                if (this.dgWrokEfficient.ItemsSource == null)
                {
                    throw new Exception("请查询后再将数据导出。");
                }
                else
                {
                    this.ExportDataToFile(this.dgWrokEfficient);
                }
            }
            catch (Exception ex)
            {
                this.wcfLogClient.ErrorAsync(((App)Application.Current).LogStr +
                                                        " ExportDate("+this.ctrlName +") " +
                                                        ex.Message.ToString() +
                                                        workEfficSelcontainer.WhereIntorLogs);
                FunctionClass.ShowMessageBox(
                    this.errorMessbox,
                    1,
                    "提示",
                   ex.Message.ToString(),
                   Colors.Gray,
                   true,
                   Visibility.Visible,
                   Visibility.Collapsed);
                return;
            }
        }

        /// <summary>
        /// 数据导出
        /// ExportDataToFile
        /// </summary>
        /// <param name="grid">带有显示格式的 grid</param>
        /// <value>10/14/2010 修改 导出功能异常</value>
        private void ExportDataToFile(DataGrid grid)
        {
            try
            {
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.DefaultExt = "csv";
                sfd.Filter = "CSV Files (*.csv)|*.csv|All files (*.*)|*.*";

                sfd.FilterIndex = 1;
                bool? ret = sfd.ShowDialog();
                if (ret == true)
                {
                    string data = DataExport.ExportDataGrid(true, grid, null, this.dataListToCSV);

                    using (System.IO.Stream stream = sfd.OpenFile())
                    {
                        using (System.IO.StreamWriter writer = new System.IO.StreamWriter(stream, System.Text.UnicodeEncoding.Unicode))
                        {
                            //由 逗号 换成 ^ ,--07/30/2010--EIDT 修改 千分位分割符用TAB替换问题
                            data = data.Replace("^", "\t");
                            writer.Write(data);
                            writer.Close();
                        }

                        stream.Close();
                    }

                    this.wcfLogClient.InfoAsync(((App)Application.Current).LogStr +
                                                        "在 "+this.ctrlName +" 查询中导出记录" +
                                                        workEfficSelcontainer.WhereIntorLogs);
                    FunctionClass.ShowMessageBox(
                      this.errorMessbox,
                      0,
                     "提示",
                     "数据已导出。",
                     Colors.Gray,
                     true,
                     Visibility.Visible,
                     Visibility.Collapsed);
                    return;
                }
                else
                {
                    return;
                }
            }
            catch (Exception ex)
            {
                this.wcfLogClient.ErrorAsync(((App)Application.Current).LogStr + 
                                                    " ExportDataToFile("+this.ctrlName +") " +
                                                    ex.Message.ToString()+
                                                    workEfficSelcontainer.WhereIntorLogs );
                FunctionClass.ShowMessageBox(
                    this.errorMessbox,
                    1,
                   "提示",
                   ex.Message.ToString(),
                   Colors.Gray,
                   true,
                   Visibility.Visible,
                   Visibility.Collapsed);
                return;
            }
        }

        #endregion 数据导出

        #region 根据屏幕的分辨率，设置图表大小

        void Content_Resized(object sender, EventArgs e)
        {
            RefreshChartShowSize();
        }

        /// <summary>
        /// 根据屏幕的分辨率，设置图表大小
        /// </summary>
        private void RefreshChartShowSize()
        {
            /*
             * App.Current.Host.Content.ActualWidth - 250: 计算长度
             * workEfficChartXMaxWidth : X轴长度
             * 
             * 前图表长度 为当X轴的最大长度 
             */

            if (workEfficChart != null)
            {
                workEfficChart.Height = App.Current.Host.Content.ActualHeight - 300 > 0 ? App.Current.Host.Content.ActualHeight - 300 : 0;

                double width = App.Current.Host.Content.ActualWidth - 250 > 0 ? App.Current.Host.Content.ActualWidth - 250 : 0;

                if (width <= 0 || workEfficChartXMaxWidth <= 0)
                {
                    workEfficChart.Width = 0;
                }
                else
                {
                    workEfficChart.Width = workEfficChartXMaxWidth + 200;
                }
            }
        }
       
        #endregion 根据屏幕的分辨率，设置图表大小
    }
}
